<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script>
	$(document).ready(function() {
		
		var projectPhaseId = '${projectPhaseId}';
		$("input[name='userId']").select2({
			placeholder: '请选择学员',
			minimumResultsForSearch: 1,
			minimumInputLength: 2,
			tags: true,
			allowClear: true,
			ajax: {
				type: 'GET',
				url: function(params) {
					return window.__CTX__.root + '/project-results/select-search?query=' + params+'&projectPhaseId=' + projectPhaseId
				},
				dataType: 'json',
				delay: 1500,
				results: function(response, page, i) {

					if(response.code == '0' || response.code == 0) {
						return {
							results: response.data.projectTrainees
						}
					} else {
						return null;
					}
				},
				cache: true
			}
		}).on("change", function(e) {
			if(e.added) {

				var id = e.added.id;

				if(id != null) {
					// ajax
					$.ajax({
						type: 'GET',
						url: window.__CTX__.root + '/project-results/select?userId=' + id + '&projectPhaseId=' + projectPhaseId,
						dataType: 'json',
						success: function(response) {

							var trainingResult = response.data.trainingResult;

							$("input[name = 'score']").val(trainingResult.score);
							$("input[name = 'absence']").val(trainingResult.absence);
							$("input[name = 'comment']").val(trainingResult.comment);
						}
					})

				} else {
					// qingkong
					$("input[name='score']").select2("val", "");
					$("input[name='absence']").select2("val", "");
					$("input[name='comment']").select2("val", "");
				}

			}
		})

	})
</script>
<div class="modal-dialog ms-modal-dialog" style="margin-top: 50px;">
	<div class="modal-content">

		<div class="modal-header">
			<button type="button" id="closeBtn" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
			<h4 class="modal-title">考勤输入</h4>
		</div>
		<form class="form-horizontal ms-form form-personal-info" method="POST" action="${ctx.host}/project-results/${projectPhaseId}/trainee-score-list" data-validate="true">

			<input type="hidden" name="_method" value="PATCH" />

			<div class="modal-body">

				<div class="form-group  umu-form-group">
					<label class="control-label col-xs-4">查询学员：</label>
					<div class="col-xs-8">
						<input type="text" class="select2 form-control" id="traineeSearchName" name="userId" value="" placeholder="请输入姓名/邮箱进行查询" autocomplete="off" tabindex="1" />
					</div>
				</div>

				<div class="form-group  umu-form-group">
					<label class="control-label col-xs-4">成绩：</label>
					<div class="col-xs-8">
						<input type="text" class="select2 form-control" name="score" placeholder="满分100分" autocomplete="off" tabindex="1" />
					</div>
				</div>
				<div class="form-group  umu-form-group">
					<label class="control-label col-xs-4">缺勤天数：</label>
					<div class="col-xs-8">
						<input type="text" class="select2 form-control" name="absence" autocomplete="off" tabindex="1" />
					</div>
				</div>
				<div class="form-group  umu-form-group">
					<label class="control-label col-xs-4">是否补考：</label>
					<div class="col-xs-8 no-border">
						是：<input type="radio" name="resit" value="true" />&nbsp;&nbsp;&nbsp;否：<input type="radio" name="resit" value="false" checked="checked" />
					</div>
				</div>
				<div class="form-group  umu-form-group">
					<label class="control-label col-xs-4">备注：</label>
					<div class="col-xs-8">
						<input type="text" class="select2 form-control" name="comment" autocomplete="off" tabindex="1" />
					</div>
				</div>

			</div>

			<div class="modal-footer">
				<button type="submit" id="btnSubmit" class="btn btn-shadow-success btn-shadow umu-btn">提交</button>
				<button type="button" id="btnCancel" class="btn btn-shadow-default btn-shadow umu-btn" data-dismiss="modal">取消</button>
			</div>
		</form>

	</div>
</div>